home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
2499.ZIP
/
TIMEIT.ZIP
/
TIMEIT.C
< prev
next >
Wrap
Text File
|
1989-02-15
|
4KB
|
123 lines
/** TIMEIT.c *********************************************************/
/* WINDOWS PROGRAM TIMER APPLICATION
by: Steve Burg
*/
/*********************************************************************/
#define NOMINMAX
#include <windows.h> /* all Windows functions */
#include <dde.h>
#include <stdlib.h> /* itoa */
#include <string.h> /* strcat & strlen */
ATOM aAppl;
long FAR PASCAL WndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam);
/* WinMain - Main loop for all Windows applications */
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine,
int nCmdShow)
{
static char szAppName[] = "Windows Timeit";
WNDCLASS WndClass;
HWND hWnd;
MSG msg;
if (!hPrevInstance)
{
/* define Window class */
lpszCmdLine[0] = '\0'; /* Remove Compiler warnings */
nCmdShow = 0;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = NULL;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = (LPSTR) szAppName;
WndClass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
WndClass.hInstance = hInstance;
WndClass.style = CS_VREDRAW | CS_HREDRAW;
WndClass.lpfnWndProc = WndProc;
/* register this new class with WINDOWS */
if (!RegisterClass((LPWNDCLASS)&WndClass))
return FALSE; /* Initialization failed */
}
/* create window */
hWnd = CreateWindow((LPSTR) szAppName, (LPSTR) szAppName,
WS_TILEDWINDOW,
0, 0, 0, 0,
(HWND)NULL, (HMENU)NULL,
(HANDLE)hInstance, (LPSTR)NULL);
/* show window (start in ICONIC state) */
ShowWindow(hWnd, SHOW_ICONWINDOW);
UpdateWindow(hWnd);
aAppl = GlobalAddAtom(szAppName);
/* main program loop */
while (GetMessage((LPMSG)&msg, NULL, 0, 0))
{
TranslateMessage((LPMSG) &msg);
DispatchMessage((LPMSG) &msg);
} /* end while GetMessage */
GlobalDeleteAtom(aAppl);
/* exit back to Windows */
return (int)msg.wParam;
} /* end WinMain */
/* WndProc - Window procedure for main window */
long FAR PASCAL WndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
char buffer[20], buf1[10];
PAINTSTRUCT ps;
RECT rect;
DWORD dwEndTime;
static DWORD dwTime;
static WORD wSec = 0, wTenthSec = 0;
static HWND hWndDDE;
/* switch on message type sent to window by Windows dispatcher */
switch(message)
{
case WM_DDE_INITIATE:
if (LOWORD(lParam) == aAppl)
{
GlobalDeleteAtom(aAppl);
hWndDDE = wParam;
dwTime = GetCurrentTime();
}
break;
case WM_DDE_TERMINATE:
if (wParam == hWndDDE)
{
dwEndTime = GetCurrentTime();
dwEndTime -= dwTime;
wSec = (WORD)(dwEndTime/1000);
wTenthSec = (WORD)((dwEndTime/100)%10);
InvalidateRect(hWnd, NULL, TRUE);
}
break;
case WM_PAINT:
BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
GetClientRect(hWnd, (LPRECT) &rect);
DrawText(ps.hdc, (LPSTR)buffer,
strlen(strcat(strcat(strcat(itoa(wSec, buffer, 10), "."),
itoa(wTenthSec, buf1, 10)), " Sec.")),
(LPRECT)&rect, DT_WORDBREAK);
EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
} /* end switch */
return 0L;
} /* end WndProc */